package com.example.limit.config;

import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.core.RulesEngineParameters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Easy Rules配置类
 */
@Configuration
public class EasyRulesConfig {
    
    /**
     * 基础规则引擎
     */
    @Bean
    public RulesEngine basicRulesEngine() {
        RulesEngineParameters parameters = new RulesEngineParameters()
            .skipOnFirstAppliedRule(false)
            .skipOnFirstFailedRule(false)
            .skipOnFirstNonTriggeredRule(false)
            .priorityThreshold(10);
        
        return new DefaultRulesEngine(parameters);
    }
    
    /**
     * 高性能规则引擎（跳过未触发规则）
     */
    @Bean
    public RulesEngine highPerformanceRulesEngine() {
        RulesEngineParameters parameters = new RulesEngineParameters()
            .skipOnFirstAppliedRule(false)
            .skipOnFirstFailedRule(false)
            .skipOnFirstNonTriggeredRule(true)  // 跳过未触发规则提高性能
            .priorityThreshold(5);
        
        return new DefaultRulesEngine(parameters);
    }
    
    /**
     * 严格模式规则引擎（遇到失败立即停止）
     */
    @Bean
    public RulesEngine strictRulesEngine() {
        RulesEngineParameters parameters = new RulesEngineParameters()
            .skipOnFirstAppliedRule(false)
            .skipOnFirstFailedRule(true)  // 遇到失败立即停止
            .skipOnFirstNonTriggeredRule(false)
            .priorityThreshold(3);
        
        return new DefaultRulesEngine(parameters);
    }
}